package com.screen.screendisplay.service.impl.dryport;

import com.screen.screendisplay.entity.dryport.DryportProdoperThroughput;
import com.screen.screendisplay.mapper.dryport.DryportProdoperThroughputMapper;
import com.screen.screendisplay.service.dryport.DryportProdoperThroughputService;
import com.screen.screendisplay.vo.dryport.ThroughputVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 吞吐量情况表 服务实现类
 * </p>
 *
 * @author xuesong
 * @since 2025-08-23
 */
@Service
public class DryportProdoperThroughputServiceImpl extends ServiceImpl<DryportProdoperThroughputMapper, DryportProdoperThroughput> implements DryportProdoperThroughputService {

    @Override
    public List<ThroughputVO> getMonthlyStatsByYear(Integer year) {
        // 从数据库查询数据
        List<DryportProdoperThroughput> entityList = baseMapper.getMonthlyStatsByYear(year);
        
        // 转换为VO对象
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return entityList.stream().map(entity -> {
            ThroughputVO vo = new ThroughputVO();
            BeanUtils.copyProperties(entity, vo);
            // 将Date类型转换为String类型
            if (entity.getDate() != null) {
                vo.setDate(sdf.format(entity.getDate()));
            }
            return vo;
        }).collect(Collectors.toList());
    }

}
